package org.witsoft.demo.graphql.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Result<T> {

    private int code;

    private String message = "ok";

    private T data;

    public static <T> Result<T> error(int code, String message){
        return (Result<T>) Result.builder().code(code).message(message).build();
    }

    public static <T> Result<T> error(String message){
        return (Result<T>) Result.builder().code(5000).message(message).build();
    }

    public static <T> Result<T> success(T data){
        return (Result<T>) Result.builder().message("ok").data(data).build();
    }

    public static <T> Result<T> success(String message){
        return (Result<T>) Result.builder().message(message).build();
    }

    public static <T> Result<T> success(T data, String message){
        return (Result<T>) Result.builder().data(data).message(message).build();
    }
}
